package com.ljtxxhwj.myblob.service.impl;

import com.ljtxxhwj.myblob.entity.Chat;
import com.ljtxxhwj.myblob.entity.ChatRecord;
import com.ljtxxhwj.myblob.mapper.ChatMapper;
import com.ljtxxhwj.myblob.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {
    @Autowired
    ChatMapper chatMapper;

    @Override
    public boolean addChat(Chat chat) {
        return chatMapper.insert(chat);
    }

    @Override
    public Chat getChatById(int chatId) {
        return chatMapper.selectById(chatId);
    }

    @Override
    public List<Chat> getMyChat(int userId) {
        return chatMapper.selectByUserId(userId);
    }

    @Override
    public boolean addChatRecord(ChatRecord chatRecord) {
        return chatMapper.insertChatRecord(chatRecord);
    }

    @Override
    public List<ChatRecord> getChatRecord(int chatId) {
        List<ChatRecord> chatRecords = chatMapper.selectChatRecord(chatId);
        if (chatRecords == null) {
            return Collections.emptyList();
        }
        return chatRecords;
    }
}
